package com.qianya.system.face.web.patient.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianya.model.common.ResultCode;
import com.qianya.model.pojo.patient.vo.PatientHisPrescriptionDetailsVO;
import com.qianya.system.face.web.patient.model.PatientFileInfo;
import com.qianya.system.face.web.patient.service.IPatientHisPrescriptionService;
import com.qianya.system.face.web.patient.model.PatientHisPrescription;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianya.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.qianya.model.common.CommonResult;
import com.qianya.model.pojo.patient.qo.PatientHisPrescriptionQO;
import com.qianya.model.pojo.patient.vo.PatientHisPrescriptionVO;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;

import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 服药日志表 前端控制器
    * </p>
*
* @author lhl
* @since 2020-07-07
*/
    @RestController
@RequestMapping("/patient/patient-his-prescription")
@Api(value = "PatientHisPrescriptionController", tags = "服药日志表接口")
@Slf4j
@Validated
public class PatientHisPrescriptionController {
    @Autowired
    private IPatientHisPrescriptionService patientHisPrescriptionService;


      /* @PutMapping(value = "/update")
    @ApiOperation("修改服药日志表")
    public CommonResult update(@RequestBody  PatientHisPrescriptionQO patientHisPrescriptionQO,HttpServletRequest request){
        PatientHisPrescription patientHisPrescription = new PatientHisPrescription();
        BeanUtils.copyProperties(patientHisPrescriptionQO,patientHisPrescription);
        return patientHisPrescriptionService.renewal(patientHisPrescription,request);
    }*/
    /*@PostMapping(value = "/save")
    @ApiOperation("添加服药日志表")
    public CommonResult save(@RequestBody  PatientHisPrescriptionQO patientHisPrescriptionQO,HttpServletRequest request){
        PatientHisPrescription patientHisPrescription = new PatientHisPrescription();
        BeanUtils.copyProperties(patientHisPrescriptionQO,patientHisPrescription);
        return patientHisPrescriptionService.create(patientHisPrescription,request);
    }*/
      @PutMapping(value = "/dispensing")
      @ApiOperation("确认发药")
      public CommonResult dispensing(@ApiParam(value = "医嘱编号",required = true)
                                     @NotBlank(message = "医嘱编号不能为空")
                                     @RequestParam(defaultValue = "",name = "hpId")String hpId,HttpServletRequest request){
          return patientHisPrescriptionService.dispensing(hpId,request);
      }
    @ApiOperation("查找服药日志表")
    @GetMapping(value = "/find")
    public CommonResult<IPage<PatientHisPrescriptionVO>> find(PatientHisPrescriptionQO patientHisPrescriptionQO,HttpServletRequest request){

        return patientHisPrescriptionService.find(patientHisPrescriptionQO);
    }
    @ApiOperation("查询医嘱")
    @GetMapping(value = "/view")
    public CommonResult<PatientHisPrescription> view(@ApiParam(value = "档案编号",required = true)
                             @NotBlank(message = "档案编号不能为空")
                             @RequestParam(defaultValue = "",name = "fileId")String fileId){
        return patientHisPrescriptionService.view(fileId);
    }
    @ApiOperation("查询今日发药记录以及发药人数")
    @GetMapping(value = "/today")
    public CommonResult<IPage<PatientFileInfo>> today(){
        return patientHisPrescriptionService.today();
    }
    @ApiOperation("根据时间和身份证号查询当天服药详情")
    @GetMapping(value = "/patientOneDayMedicineDateils")
    public CommonResult<PatientHisPrescriptionDetailsVO> patientOneDayMedicineDateils(@ApiParam(value = "身份证号",required = true)
                                                           @NotBlank(message = "身份证号不能为空")
                                                           @RequestParam(defaultValue = "",name = "fileIdentityCard")String fileIdentityCard
                                                       , @ApiParam(value = "日期(yyyy-MM-dd)",required = true)
                                                           @NotBlank(message = "日期不能为空")
                                                @RequestParam(defaultValue = "",name = "time")String time){
        if (!DateUtils.valiDateTimeWithLongFormat(time)){
            return CommonResult.error(ResultCode.ERROR,"日期格式不对");
        }
        return patientHisPrescriptionService.patientOneDayMedicineDateils(fileIdentityCard,time);
    }
 }
